{% extends "business/business_base.html" %}
{% block title %}{{ '审核车源' if data.state == 0 else '车辆详情' }}{% endblock %}
{% block head %} 
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/upload.css') }}">
{% endblock %}
{% block page_content %}

{{ super() }}

<div class="modal fade" id="RejectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">拒绝车辆</h4>
			</div>
			<div class="modal-body">
				<form role="form" id="RejectForm">
					<label for="reason">拒绝原因</label>
					<textarea class="form-control" id="reason" name="reason" cols=20 rows=5 required></textarea>
					<input type='hidden' name='number' id='number' >
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-success" onclick="reject('{{ data.number }}')">确定</button>
				<button type="button" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">取消</button>
			</div> 
		</div>
	</div><!-- /.modal-dialog -->
</div>
<div class="modal fade" id="PassModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">通过审批</h4>
			</div>
			<div class="modal-body">
				<center>确定通过该车辆的审批吗？</center>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-danger" onclick="pass('{{ data.number }}')">确定</button>
				<button type="button" class="btn btn-success" data-dismiss="modal" aria-hidden="true">取消</button>
			</div> 
		</div>
	</div><!-- /.modal-dialog -->
</div>

<h1 class="page-header">{{ '审核车源' if data.state == 0 else '车辆详情' }}</h1>
<div class="row">
	<div class="sh-upload-tab-con">
		<div class="upload-tab-list">
			<div class="sh-frame-number sh-car-list">
				<span class="sh-tab-name">车架号：</span>
				<input id="frame_number" type="text" maxlength="17" value="{{ data.frame_number }}" readonly>
			</div>
			<div class="sh-frame-number sh-car-list">
				<span class="sh-tab-name">车型：</span>
				<input id="car_type" type="text" value="{{ eval(op.hget('car_type', data.car_type))[0] }}" readonly>
			</div>
			<div class="sh-frame-number sh-car-list">
				<span class="sh-tab-name">品牌：</span>
				<input id="model" class="brand-input" type="text" value="{{ data.model }}" readonly>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">指定车型：</span>
				<input id="specific" type="text" value="{{ '是' if data.specific else '否'}}" readonly>
			</div>
			<div class="sh-car-price sh-car-list">
				<span class="sh-tab-name">出售价格：</span>
				<input id="price" class="sh-car-input" type="text" value="{{ data.price }}" readonly>
				<span class="sh-car-txt">万元</span>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">变速箱类型：</span>
				<input id="gearbox" class="sh-car-input" type="text" value="{{ eval(op.hget('gearbox', data.type_of_gearbox))[0] }}" readonly>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">排放标准：</span>
				<input id="standard" class="sh-car-input" type="text" value="{{ eval(op.hget('standard', data.emission_standard))[0] }}" readonly>
			</div>
			<div class="sh-car-sit sh-car-list">
				<span class="sh-tab-name">排量：</span>
				<input id="displacement" class="sh-car-input" type="text" value="{{ data.displacement }}" readonly>
				<span class="sh-car-txt">L</span>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">颜色：</span>
				<input id="color" class="sh-car-input" type="text" value="{{ eval(op.hget('color', data.color))[0] }}" readonly>
			</div>
			<div class="sh-car-sit sh-car-list">
				<span class="sh-tab-name">座位数：</span>
				<input id="seat" class="sh-car-input" type="text" value="{{ data.number_of_seats}}" readonly>
				<span class="sh-car-txt">座</span>
			</div>
			<div class="sh-car-supplement sh-car-list">
				<span class="sh-tab-name">补充说明：</span>
				<textarea id="desc" readonly>{{ data.description }}</textarea>
			</div>
			{% if not data.new %}		
			<div class="sh-car-list">
				<span class="sh-tab-name">首次上牌时间：</span>
				<input type="text" class="sh-car-input" value="{{ data.first_licensing_date }}" id="licensing_date" readonly>
			</div>
			<div class="sh-car-list" style="position:relative;">
				<span class="sh-tab-name">上牌地：</span>
				<input type="text" class="sh-car-input" id="licensing_place" value="{{ data.licensing_place }}" readonly>
			</div>
			<div class="sh-car-age sh-car-list">
				<span class="sh-tab-name">车龄：</span>
				<input id="month" class="sh-car-input" type="text" value="{{ data.age_of_car }}" readonly>
				<span class="sh-car-txt">月</span>
			</div>
			<div class="sh-car-drive sh-car-list">
				<span class="sh-tab-name">行驶里程数：</span>
				<input id="mileage" class="sh-car-input" type="text" value="{{ data.mileage }}" readonly>
				<span class="sh-car-txt">公里</span>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">年检：</span>
				<input type="text" class="sh-car-input" value="{{ data.annual_inspection }}" id="annual" readonly>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">交强险：</span>
				<input type="text" class="sh-car-input" value="{{ data.compulsory_insurance }}" id="compulsory" readonly>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">商业险：</span>
				<input type="text" class="sh-car-input" id="commercial" value="{{ data.commercial_insurance if data.commercial_insurance else '无'}}" readonly>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">过户次数：</span>
				<input id="transfer" class="sh-car-input" type="text" value="{{ data.transfer_times }}" readonly>
				<span class="sh-car-txt">次</span>
			</div>
			{% endif %}
			<div class="sh-car-list">
				<span class="sh-tab-name">联系人：</span>
				<input id="contact" class="sh-car-input" type="text" value="{{ data.contact }}" readonly>
			</div>
			<div class="sh-car-list">
				<span class="sh-tab-name">联系电话：</span>
				<input id="phone" class="sh-car-input" type="text" value="{{ data.phone }}" readonly>
			</div>
			<div class="sh-frame-number sh-car-list" >
				<span class="sh-tab-name">看车地址：</span>
				<input id="address" class="sh-car-input" style="width:400px;"type="text" value="{{ data.address }}" readonly>
			</div>
			<div class="row sh-car-list cleafix" >
				<div class="sh-tab-name fl">车辆实拍照片：</div>
				<div style="margin-left:100px;">
					<div>
						{% for url in photos['car'] %}
						<div style="display:inline-block;margin-right:20px;margin-bottom:10px;">
							<img style="border-radius:5px;width:176px;height:110px;" src="{{ url }}">
						</div>
						{% endfor %}
					</div>
				</div>
			</div>
			{% if not data.new %}
			<div class="row sh-car-list cleafix" >
				<div class="sh-tab-name fl">车辆检测报告：</div>
				<div style="margin-left:100px;">
					<div>
						{% for url in photos['check'] %}
						<div style="display:inline-block;margin-right:20px;margin-bottom:10px;">
							<img style="border-radius:5px;width:176px;height:110px;" src="{{ url }}">
						</div>
						{% endfor %}
					</div>
				</div>
			</div>
			<div class="row sh-car-list cleafix" >
				<div class="sh-tab-name fl">证件实拍：</div>
				<div style="margin-left:100px;">
					<div>
						{% for url in photos['other'] %}
						<div style="display:inline-block;margin-right:20px;margin-bottom:10px;">
							<img style="border-radius:5px;width:176px;height:110px;" src="{{ url }}">
						</div>
						{% endfor %}
					</div>
				</div>
			</div>
			{% endif %}
			{% if data.state == 2 %}
			<div class="sh-car-supplement sh-car-list">
				<span class="sh-tab-name">拒绝原因：</span>
				<textarea id="reason" readonly>{{ reason }}</textarea>
			</div>
			{% endif %}
		</div>
	</div>
	{% if data.state == 0 %}
	<div>
	<center>
	<button type="button" class="btn btn-success" data-target="#PassModal" data-toggle="modal">通过</button>
	<button type="button" class="btn btn-danger" data-target="#RejectModal" data-toggle="modal">拒绝</button>
	</center>
	</div>
	{% endif %}
</div>
{% endblock %}
{% block scripts  %}
{{ super() }}
<script>
{% if data.state == 0 %}
    $('#nav_review').attr('class', 'active');
{% else %}
    $('#nav_car').attr('class', 'active');
{% endif %}

var state = -1;
var pass = function(number){
	$("#PassModal").modal('hide');
        $.ajax({
            url: "/business/car/review/pass/",
            data: {"number": number},
            type: "POST",
            dataType:"text",
            success: function(data) {
                json = eval("("+data+")");
		state = json.state;
                if(json.state === 0){
			$('#msg').html("操作成功");
			$('#msg_icon').removeAttr('class');
			$('#msg_icon').attr('class', 'glyphicon glyphicon-ok-sign');
                }
		else{
			$('#msg').html("操作失败，" + json.msg);
			$('#msg_icon').removeAttr('class');
			$('#msg_icon').attr('class', 'glyphicon glyphicon-remove-sign');
		}
            },
	    error: function(xhr, error){
		state = -1;
		$('#msg_icon').removeAttr('class');
		$('#msg_icon').attr('class', 'glyphicon glyphicon-remove-sign');
		$('#msg').html("操作失败，服务器发生错误");
	    }
        });
	$('#MsgModal').modal();
	return;
};

var reject = function(number){
	var reason = $('#reason').val();
	if(reason===""){
		$("#msg").html("请填写拒绝原因");
                $('#MsgModal').modal();
		return;
	}
        $.ajax({
            url: "/business/car/review/reject/",
            data: {"number": number, "reason": reason},
            type: "POST",
            dataType:"text",
            success: function(data) {
		$("#RejectModal").modal('hide');
                json = eval("("+data+")");
		state = json.state;
                if(json.state === 0){
			$('#msg').html("操作成功");
			$('#msg_icon').removeAttr('class');
			$('#msg_icon').attr('class', 'glyphicon glyphicon-ok-sign');
                }
		else{
			$('#msg').html("操作失败，" + json.msg);
			$('#msg_icon').removeAttr('class');
			$('#msg_icon').attr('class', 'glyphicon glyphicon-remove-sign');
		}
            },
	    error: function(xhr, error){
		state = -1;
		$('#msg_icon').removeAttr('class');
		$('#msg_icon').attr('class', 'glyphicon glyphicon-remove-sign');
		$('#msg').html("操作失败，服务器发生错误");
	    }
        });
	$('#MsgModal').modal();
	return;
};

$(document).ready(function(){
	
	$('#MsgModal').on('hidden.bs.modal', function () {
		if(state === 0){
			window.location.href = '/business/car/review/list/'
		}
	})
});

</script>
{% endblock %}

